/*
 * @author java_deng
 * @date 2024/12/4 10:29
 * @description
 */
package org.kaka.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.kaka.dto.FileDto;
import org.kaka.mapper.SwiperMapper;
import org.kaka.po.FilePo;
import org.kaka.service.FileService;
import org.kaka.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FileServiceImpl implements FileService {
    @Autowired
    private SwiperMapper swiperMapper;

    @Override
    public void save(FileDto fileDto) {
        swiperMapper.insert(fileDto);
    }

    public List<FileDto> fileDtoList(Integer type){
        return swiperMapper.list(type);
    }

    public Page<FileDto> fileDtoListByPage(FilePo filePo) {
        if(filePo.getPageIndex()==null){
            filePo.setPageIndex(1);
        }
        if(filePo.getPageSize()==null){
            filePo.setPageSize(10);
        }
        Page<FileDto> objects = PageHelper.startPage(filePo.getPageIndex(), filePo.getPageSize());
        swiperMapper.totalList(filePo.getType());
        return objects;
    }

    public void updateDelete(Integer id) {
        FileDto newFile = new FileDto();
        FileDto fileDto = swiperMapper.selectById(id);
        if(fileDto.getIsDeleted()==1){
            newFile.setIsDeleted(2);
        } else if (fileDto.getIsDeleted() == 2) {
            newFile.setIsDeleted(1);
        }
        newFile.setId(id);
        swiperMapper.updateById(newFile);
    }

    public void delete(Long id) {
        swiperMapper.deleteById(id);
    }
}
